#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2010;
typedef int LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
string p[10]={"1110111","0010010","1011101","1011011","0111010","1101011","1101111","1010010","1111111","1111011"};
string a[maxn];
bool st[maxn][maxn];
bool flag=1;
LL ans[maxn];
void dfs(LL pos,LL k,LL n){
    if(flag==0||k<0){
        return;
    }
    if(pos==n+1){
        if(k==0){
            flag=0;
            for(LL i=1;i<=n;i++){
                cout<<ans[i];
            }
            cout<<"\n";
            return;
        }
        else return;
    }
    if(st[pos][k]) return;
    for(LL i=9;i>=0;i--){
        bool state=1;
        LL cnt=0;
        for(LL j=0;j<7;j++){
            if(p[i][j]=='1'&&a[pos][j]=='0') cnt++;
            else if(p[i][j]=='0'&&a[pos][j]=='1'){
                state=0;
                break;
            }
        }
        if(0==state) continue;
        ans[pos]=i;
        dfs(pos+1,k-cnt,n);
        ans[pos]=0;
    }
    if(1==flag) st[pos][k]=true;
}
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL n,k;cin>>n>>k;
  for(LL i=1;i<=n;i++){
     cin>>a[i];
  }
  dfs(1,k,n);
  if(flag==1){
    cout<<"-1"<<"\n";
  }
return 0;
}
